﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Evolution.Structure.Globe;
using Evolution.Structure;

namespace GameProject.ViewModel
{
    class MainWindowViewModel : ViewModelBase
    {
        public UserControl MainView
        {
            get { return _MainView; }
            set {
                _MainView = value;
                base.onPropertyChanged("MainView");
            }
        }
        private UserControl _MainView;

        public UserControl GameMenu
        {
            get
            {
                if (_GameMenu == null)
                {
                    _GameMenu = new GameMenu();
                    _GameMenu.DataContext = new GameMenuViewModel(this);
                }
                return _GameMenu;
            }
        }
        private UserControl _GameMenu;

        public UserControl PlayerMenu
        {
            get
            {
                if (_PlayerMenu == null)
                {
                    _PlayerMenu = new Playername();
                    _PlayerMenu.DataContext = new PlayerNameViewModel(this);
                }
                return _PlayerMenu;
            }
        }
        private UserControl _PlayerMenu;

        private UserControl _MainGame;

        public UserControl EncyclopediaMenu
        {
            get
            {
                if (_EncyclopediaMenu == null)
                {
                    _EncyclopediaMenu = new EncyclopediaView();
                    _EncyclopediaMenu.DataContext = new EncyclopediaViewViewModel(this);
                }
                return _EncyclopediaMenu;
            }
        }
        private UserControl _EncyclopediaMenu;

        public UserControl WorldBuilder
        {
            get
            {
                if (_WorldBuilder == null)
                {
                    _WorldBuilder = new WorldBuilder();
                    _WorldBuilder.DataContext = new WorldBuilderViewModel(this);
                }
                return _WorldBuilder;
            }
        }
        private UserControl _WorldBuilder;

        public void OpenWorldBuilder()
        {
            MainView = WorldBuilder;
        }

        public void OpenEncyclopdia()
        {
            MainView = EncyclopediaMenu;
        }

        public void OpenGameMenu()
        {
            MainView = GameMenu;
        }

        public void OpenPlayerMenu()
        {
            MainView = PlayerMenu;
        }

        public void OpenMainGame()
        {
            MainView = _MainGame;
        }

        public void GenerateAndOpenWorld(int worldSize, int waterLand, int forest, int mountain, int grass)
        {
            World myWorld = WorldGenerator.generateWorld(worldSize, waterLand, forest, mountain, grass);

            _MainGame = new MainGame();
            _MainGame.DataContext = new ViewModel.MainGameViewModel();

            OpenMainGame();
        }

        public MainWindowViewModel()
        {
            GlobalVar.Encyclopdia = new Encyclopedia();
            OpenPlayerMenu();
        }
    }
}
